package com.petAdoption.manager.controller;


import com.petAdoption.manager.entity.Pettype;
import com.petAdoption.manager.service.IPettypeService;
import com.petAdoption.manager.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王倩茹
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/pettype")
public class PettypeController {
    @Resource
    private IPettypeService pettypeService;

    @Resource
    private Result result;

    @GetMapping("/findAll")
    public Result findAll(){
        List<Pettype> list = pettypeService.findAll();
        if(list!=null && !list.isEmpty()){
            return result.success("查找成功",list);
        }
        return result.fail("查找失败");
    }

    @DeleteMapping("/delPetType")
    public Result delPetType(Integer pettypeId){
        int rows = pettypeService.delPetType(pettypeId);
        if(rows>0){
            return result.success("删除成功",rows);
        }else {
            return result.fail("删除失败");
        }
    }

    @PostMapping("/addPetType")
    public Result addPetType(@RequestBody Pettype pettype){
        int rows = pettypeService.addPetType(pettype);
        if(rows>0){
            return result.success("添加成功",rows);
        }else {
            return result.fail("添加失败");
        }
    }


    @PutMapping("/updatePetType")
    public Result updatePetType(@RequestBody Pettype pettype){
        int rows = pettypeService.updatePetType(pettype);
        if(rows>0){
            return result.success("修改成功",rows);
        }else {
            return result.fail("修改失败");
        }
    }

}
